package com.locus.tools;

import java.util.Set;
import android.content.Context;
import android.content.Intent;
import android.content.IntentReceiver;

import com.locus.tools.location.GPSResponse;
import com.locus.tools.location.LocalLocation;
import com.locus.tools.xmpp.GTalkAgent;

/**
 * A manager to deal with any locus specific requests. 
 * @author jfredett
 *
 */
public class LocusIntentManager extends IntentReceiver {
	
	/** 
	 * How to react to each incoming intent.
	 * <p>
	 * Since each request has a specific category, we can simply match against a single category, and
	 * we can uniquely determine intent.
	 * @param ct <br> the current context
	 * @param intent <br> an intent we've recieved
	 */
	public void onReceiveIntent(Context ct, Intent intent) {
		try {
			GTalkAgent agent = new GTalkAgent(ct);
			Set<String> intentCategories = intent.getCategories();
			LocalLocation myLocation = new LocalLocation(ct, "My Location");
			
			// these are the days I wish I had pattern matching and HOFs.
			// *cough* map (react) (filter withIntentFilter list_of_intents)
			// myreact MyIntent1 = foo
			// myreact _ = ignore
			// Intent Filtering, recieving, and reacting in four lines, thank you Haskell.
			
			// receiving requests for GPS coords, for now we respond w/o prejudice
			if (intentCategories.contains(LocusConstants.GPS_Request)) {
				// TODO:: Set up for blocking contacts, forcing contacts, spoofing, etc.
				// create the response via the ISendable interface
				GPSResponse response = createGPSResponse(myLocation);
				agent.sendMessage(response);
			} 
			else if (intentCategories.contains(LocusConstants.GPS_Response)) {
				// this is handled within the RemoteLocation class.
				return;
			}
		}
		catch (Exception e) {
			return;
		}
	}


	private GPSResponse createGPSResponse(LocalLocation myLocation) {
		// TODO:: figure this out.
		return null;
	}
	
}
